//
//  DsErErViewController.m
//  Tour
//
//  Created by 张张烨 on 16/3/9.
//  Copyright © 2016年 张中烨. All rights reserved.
//

#import "DsErErViewController.h"
#import "DsErErCell.h"
#import "DsErErModel.h"
#import "LCAFNetWorking.h"
#import "DserXiangqingVC.h"
#import "DsErErModeler.m"
@interface DsErErViewController ()<UIScrollViewDelegate,UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, strong) UITableView *myTableView;

@property (nonatomic, strong) DsErErModel *model1;


@property (nonatomic, strong) NSMutableArray *array;

@property(nonatomic,assign)NSInteger i;

@end

@implementation DsErErViewController




- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.array = [NSMutableArray array];
    self.model1 = [[DsErErModel alloc]init];
    [self data];
    [self tableView1];
    
  
}



- (void)data
{
    
    [AFNModel GETWithHandler:[NSString stringWithFormat:@"http://baobab.wandoujia.com/api/v3/videos?start=%ld&num=10&categoryName=旅行&strategy=date&udid=94ed1e252c3d48b7af407c8517fe5af488693e55&vc=83&vn=1.12.1&deviceModel=eyepetizer_le_market&last_channel=eyepetizer_le_market",_i] completion:^(id result) {
//        NSDictionary *dic =result;
//        [self.model1 setValuesForKeysWithDictionary:dic];
//        NSLog(@"%@", self.model1);
        
        if (0 == _i) {
            [_array removeAllObjects];
        }
        for (NSDictionary *dic in result[@"itemList"]) {
            DsErErModeler *d = [DsErErModeler modelWithDic:dic];
            [self.array addObject:d];
        }
        [self.myTableView reloadData];
        
    }];
 
}


- (void)tableView1
{
    self.myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGH - (80 *GAO))];
    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;
    self.myTableView.backgroundColor = [UIColor grayColor];
    self.myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;//取消分割线
    [self.view addSubview:self.myTableView];
    
    [self.myTableView registerClass:[DsErErCell class] forCellReuseIdentifier:@"cell"];
    
    //下拉刷新
    MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        _i = 0;
        // 刷新
        //        self.isSj = NO;
        [self data];
        
        //新版本是 MJ_header
        [_myTableView.mj_header endRefreshing];
        
    }];
    //设置刷新控件
    self.myTableView.mj_header = header;
    
    
    /**<  加载 */
    MJRefreshAutoFooter *footer = [MJRefreshAutoFooter footerWithRefreshingBlock:^{
        
        _i += 10;
        
        [self data];
        
  
        
        [_myTableView.mj_footer endRefreshing];
    }];
    self.myTableView.mj_footer = footer;
    
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.array.count;
}



-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    DsErErCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.model = _array[indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    DserXiangqingVC *next = [[DserXiangqingVC alloc]init];
    
    next.modle1111 = [_array objectAtIndex:indexPath.row];
    next.row = indexPath.row;
    [self.navigationController pushViewController:next animated:YES];
}








-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 250 * GAO;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    
    NSArray<DsErErCell *> *array = [self.myTableView visibleCells];
    [array enumerateObjectsUsingBlock:^(DsErErCell * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [obj cellOffset];
    }];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
